Javascript Output :
We have following ways through that we can display the output from javascript
- document.getElementById("demo").innerHTML = 1+0; property of innerHTML of HTML to display the data..
- document.write("Pavan"); will be using for testing
- <button type="button" onclick="document.write('Pavan')"> it will delete all the html and show the output
- window.alert("Pavan"); //to show data in alert
- console.log("Pavan"); //Debuging purpose
Instructions:
Programming is nothing but the instrcution given by us to machine.
insruction are in the form of statements
javascript is nothing but list of statements eecuted from top to bottom
Statements contains: values,expressions,operators,comments and keywords.
Semicolon is used to indentify the end of statement.
we can break the line after operator.
Keywords:
- break
- continue
- debugger
- do..while
- for
- function
- if..else
- return
- switch
- try..catch
- var :tells the browser to create a variable
Syntax
We have 2 types of values i.e.
1.Literals (hardcoded value or constant value)
2.Values (varible values)
its a case sensetaive..
Var, VAR and var is different
Lastname and lastname are different.
var y;
var f,g,h;
f=g+h;
g="P"+"a";
Variables:
Variables are for storing the data value.
Variables must be unique.
Variables created without the keyword var, are always global.
Variable Rules:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
A variable declared without a value will have the value undefined.
2 types of Variables
1.Local Variable : can be access withing the block
2.Global Variable : can access through out the page
Operators:
= is the assignment operator and == is the equal operator
++ increment
-- decrement
null === undefined // false
null == undefined //true
() operator invokes the function
Notes:
function without () will return the function definition instead of the function result
Data Type:
Primitive Data Type (normal data types which are without properties and methods)
String
Number
Bolean
Undefined
Null
Non Primitive Data Types:
Object
Array
RegExp
typeof undefined // undefined
typeof null // object
Function: for reusability of code
We invoke the function on
- any event occurs (on click of user)
- () from JavaScript code
- Automatically (self invoked)
Events:
- onchange
- onclick
- onmouseover
- onmouseout
- onkeydown
- onload
Object:
var training = {
trainername: "Abel",
skill : "Servicenow",
id : 111,
trainerwithskill : function() {
return this.trainername + " " + this.trainername;
}
};
var t=training.trainerwithskill(); //function value
var t=training.trainerwithskill; //function defination
var t=training.skill;
var t=training["skill"];